/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cparc;

import com.mysql.jdbc.Statement;
import java.sql.ResultSet;

/**
 *
 * @author Administrador
 */
public class log {
    
    

    //construtor
    public log(String opcao, String nomeUsuario, String cont, String sql){

      
        if (opcao.equals("raca_insert")){

            String valores[] = cont.split(",");
            String acao = "O USUARIO "+nomeUsuario+" ADICIONOU A RACA COD: "+valores[0]+" NOME: "+valores[1];

        Statement stm = null;
        String result = null;
        String consulta = "INSERT INTO CPARC.LOG_SIMP (DATA_LOG,USUARIO,ACAO,SQL_LOG) VALUES (CURRENT_TIMESTAMP(),'"+nomeUsuario+"','"+acao+"', '"+sql+"')";
        
        try  {
        stm = (Statement) conexao.getConnection(true).createStatement();
        int rs = stm.executeUpdate(consulta);

        }
        catch(Exception e){
            String status = e.getMessage();
            System.out.println(status);
        }



        }
        else if (opcao.equals("raca_update")){

            String valores[] = cont.split(",");
            String acao = "O USUARIO "+nomeUsuario+" ALTEROU A RACA COD: "+valores[0]+" NOME: "+valores[1];

            Statement stm = null;
            String result = null;
            String consulta = "INSERT INTO CPARC.LOG_SIMP (DATA_LOG,USUARIO,ACAO,SQL_LOG) VALUES (CURRENT_TIMESTAMP(),'"+nomeUsuario+"','"+acao+"', '"+sql+"')";

            try  {
                stm = (Statement) conexao.getConnection(true).createStatement();
                int rs = stm.executeUpdate(consulta);

            }
            catch(Exception e){
                String status = e.getMessage();
                System.out.println(status);
            }
        }
        else if(opcao.equals("raca_delete")){

            String valores[] = cont.split(",");
            String acao = "O USUARIO "+nomeUsuario+" EXCLUIU A RACA COD: "+valores[0]+" NOME: "+valores[1];

            Statement stm = null;
            String result = null;
            String consulta = "INSERT INTO CPARC.LOG_SIMP (DATA_LOG,USUARIO,ACAO,SQL_LOG) VALUES (CURRENT_TIMESTAMP(),'"+nomeUsuario+"','"+acao+"', '"+sql+"')";

            try  {
                stm = (Statement) conexao.getConnection(true).createStatement();
                int rs = stm.executeUpdate(consulta);
            }
            catch(Exception e){
                String status = e.getMessage();
                System.out.println(status);
            }

        }
    }



}
